#include "line_mdle.h"
#include "ui_line_mdle.h"

line_mdle::line_mdle(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::line_mdle)
{
    ui->setupUi(this);
    // --------------------------------------------
    // 创建IO
    table = new QTableWidgetSave(8,4,this);
    ui->layout_table->addWidget(table);
    // --------------------------------------------
    // 注册连线的空间信息
    table->setItem(1-1, 1-1, new QTableWidgetItem(QString("line_name")));
    table->setItem(1-1, 2-1, new QTableWidgetItem(QString("line")));
    table->setItem(2-1, 1-1, new QTableWidgetItem(QString("line_code")));
    table->setItem(2-1, 2-1, new QTableWidgetItem(QString("00000000")));
    table->setItem(3-1, 1-1, new QTableWidgetItem(QString("site_x0")));
    table->setItem(3-1, 2-1, new QTableWidgetItem(QString("1")));
    table->setItem(4-1, 1-1, new QTableWidgetItem(QString("site_y0")));
    table->setItem(4-1, 2-1, new QTableWidgetItem(QString("1")));
    table->setItem(5-1, 1-1, new QTableWidgetItem(QString("site_x1")));
    table->setItem(5-1, 2-1, new QTableWidgetItem(QString("5")));
    table->setItem(6-1, 1-1, new QTableWidgetItem(QString("site_y1")));
    table->setItem(6-1, 2-1, new QTableWidgetItem(QString("5")));


}

line_mdle::~line_mdle()
{
    delete ui;
}

QList<int> line_mdle::getSite()
{
    QList<int> site;
    site.append(table->item(3-1,2-1)->text().toInt());
    site.append(table->item(4-1,2-1)->text().toInt());
    site.append(table->item(5-1,2-1)->text().toInt());
    site.append(table->item(6-1,2-1)->text().toInt());
    return site;
}

void line_mdle::setSite(int x0, int y0, int x1, int y1) //设置线的位置
{
    table->item(3-1,2-1)->setText(QString::number(x0));
    table->item(4-1,2-1)->setText(QString::number(y0));
    table->item(5-1,2-1)->setText(QString::number(x1));
    table->item(6-1,2-1)->setText(QString::number(y1));
}
void line_mdle::setName(QString dev_name)
{
    table->item(1-1,2-1)->setText(dev_name);
}

void line_mdle::setCode(QString dev_code)
{
    table->item(2-1,2-1)->setText(dev_code);
}

void line_mdle::save(QString &fileName)
{
    table->exportToCsv(fileName);
}

void line_mdle::load(QString &fileName)
{
    table->importFromCsv(fileName);
}
QString line_mdle::getName()
{
    return table->item(1-1,2-1)->text();
}

QString line_mdle::getCode()
{
    return table->item(2-1,2-1)->text();
}
